#include "../../mqserver/mq_queue.hpp"
#include <gtest/gtest.h>

bitmq::MsgQueueManager::ptr mqmp;

class QueueTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        mqmp = std::make_shared<bitmq::MsgQueueManager>("./data/meta.db");
    }

    virtual void TearDown() override 
    {
        //mqmp->clear();
    }
};

// TEST(queue_test, insert_test)
// {
//     std::unordered_map<std::string, std::string> map1;
//     std::unordered_map<std::string, std::string> map2 = {{"k1", "v1"}, {"k2", "v2"}};
//     mqmp->declareQueue("queue1", true, false, false, map1);
//     mqmp->declareQueue("queue2", true, false, false, map1);
//     mqmp->declareQueue("queue3", true, false, false, map1);
//     mqmp->declareQueue("queue4", true, false, false, map1);
//     mqmp->declareQueue("queue5", true, false, false, map2);
//     mqmp->declareQueue("queue6", true, false, false, map2);

//     ASSERT_EQ(mqmp->size(), 6);
// }


TEST(queue_test, select_test)
{
    ASSERT_EQ(mqmp->exists("queue1"), true);
    ASSERT_EQ(mqmp->exists("queue2"), false);
    ASSERT_EQ(mqmp->exists("queue3"), true);
    ASSERT_EQ(mqmp->exists("queue4"), true);
    ASSERT_EQ(mqmp->exists("queue5"), true);
    ASSERT_EQ(mqmp->exists("queue6"), true);

    bitmq::MsgQueue::ptr mqp1 = mqmp->selectQueue("queue3");
    ASSERT_EQ(mqp1->name, "queue3");
    ASSERT_EQ(mqp1->durable, true);
    ASSERT_EQ(mqp1->exclusive, false);
    ASSERT_EQ(mqp1->auto_delete, false);
    ASSERT_EQ(mqp1->getArgs(), "");

    bitmq::MsgQueue::ptr mqp2 = mqmp->selectQueue("queue5");
    ASSERT_EQ(mqp2->name, "queue5");
    ASSERT_EQ(mqp2->durable, true);
    ASSERT_EQ(mqp2->exclusive, false);
    ASSERT_EQ(mqp2->auto_delete, false);
    ASSERT_EQ(mqp2->getArgs(), "k1=v1&k2=v2");
}

TEST(queue_test, remove_test)
{
    mqmp->deleteQueue("queue2");
    bitmq::MsgQueue::ptr mqp = mqmp->selectQueue("queue2");
    ASSERT_EQ(mqp.get(), nullptr);
}

int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new QueueTest);
    RUN_ALL_TESTS();
    return 0;
}